import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:sports_new/controller/match/list/match_page_logic.dart';
import 'package:sports_new/controller/service/config_service.dart';
import 'package:sports_new/resources/colours.dart';
import 'package:sports_new/resources/styles.dart';
import 'package:sports_new/utils/routes.dart';
import 'package:sports_new/utils/widget_utils.dart';
import 'package:sports_new/widgets/base/qkd_widget.dart';
import 'package:visibility_detector/visibility_detector.dart';

import '../../../widgets/base/qkd_text.dart';

class LqOddsConfigPage extends StatefulWidget {
  const LqOddsConfigPage({super.key});

  @override
  State<LqOddsConfigPage> createState() => _LqOddsConfigPageState();
}

class _LqOddsConfigPageState extends State<LqOddsConfigPage> {
  LqConfig config = Get.find<ConfigService>().lqConfig;
  ConfigService configService = Get.find<ConfigService>();
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: Styles.appBar(title: QkdText('篮球指数设置')),
      backgroundColor: Colours.scaffoldBg,
      body: VisibilityDetector(
        key: Key('SoccerOddsConfigPage'),
        onVisibilityChanged: (info) {
          if (!info.visibleBounds.isEmpty) {
            final matchController =
                Get.find<MatchPageLogic>().getMatchController();
            matchController.updateView();
            update();
          }
        },
        child: Padding(
          padding: EdgeInsets.symmetric(horizontal: 8),
          child: ListView(children: [
            SizedBox(height: 10),
            QkdWidget.switchCell('指数', config.lqList1 == 1, onTap: () {
              config.lqList1 = (config.lqList1 == 1 ? 0 : 1);
              update();
              configService.update(ConfigType.zqList1, config.lqList1);
              final matchController =
                  Get.find<MatchPageLogic>().getMatchController();
              matchController.updateView();
            }),
            SizedBox(height: 10),
            Styles.card(
                child: Column(
              children: [
                QkdWidget.cell(
                    '指数类型',
                    config.lqList7
                        .map((e) => configService.lqOddsType[e])
                        .toList()
                        .join(' | '),
                    isCard: false, onTap: () {
                  Get.toNamed(Routes.lqOddsType);
                }),
                QkdWidget.seperateLine(),
                QkdWidget.cell(
                    '指数公司',
                    configService.oddsCompany!
                        .firstWhere((element) => element.id == config.lqList8)
                        .name!,
                    isCard: false, onTap: () {
                  Get.toNamed(Routes.oddsCompany, arguments: 1);
                }),
                QkdWidget.seperateLine(),
                QkdWidget.cell('指数显示', config.lqList9 == 0 ? '初始' : '即时',
                    isCard: false, onTap: () {
                  Get.toNamed(Routes.oddsShow, arguments: 1);
                }),
              ],
            ))
          ]),
        ),
      ),
    );
  }
}
